package edu.hawaii.webspider;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.Locale;
import java.util.logging.LogRecord;

/**
 * A formatter for the WebSpider.
 * 
 * @author Laura Matsuo
 *
 */
public class WebSpiderFormatter extends Formatter {
  /**
   * Formats the record so that it displays a date stamp in the form HH:mm:ss:SSS (S = miliseconds).
   * This method is based on the format method in package 
   * org.hackystat.utilities.logger.OneLineFormatter; 
   *
   * @param record  A log record.
   * @return        The formatted message string.
   */
  @Override
  public String format(LogRecord record) {
    StringBuffer buff = new StringBuffer();
    
    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSS", Locale.US);
    buff.append(dateFormat.format(new Date()));
    buff.append("  ");

    buff.append(record.getMessage());
    buff.append(System.getProperty("line.separator"));
    buff.append(System.getProperty("line.separator"));

    return buff.toString();
  }
}
